package com.ktmall.ktmalluijava.service.impl;

import com.ktmall.ktmalluijava.mapper.SkuMapper;
import com.ktmall.ktmalluijava.pojo.Sku;
import com.ktmall.ktmalluijava.service.SkuService;
import com.ktmall.ktmalluijava.utils.Page;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/5/19 上午9:38
 */
@Service
public class SkuServiceImpl implements SkuService {

    @Resource
    private SkuMapper skuMapper;
    /**
     * 获取分页对象
     *
     * @param goodsId
     * @param stockSku
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public Page<Sku> getPage(Integer goodsId, String stockSku, Integer pageNo, Integer pageSize) {
        Page<Sku> page = new Page<>();
        page.setPageSize(pageSize);
        page.setTotalCount(skuMapper.count(goodsId,stockSku));
        page.setPageNo(pageNo);
        int offset = (page.getPageNo()-1)*page.getPageSize();
        page.setData(skuMapper.select(goodsId,stockSku,offset,page.getPageSize()));
        return page;
    }

    /**
     * 添加
     *
     * @param sku
     * @return
     */
    @Override
    public int add(Sku sku) {
        return skuMapper.add(sku);
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Override
    public Sku detail(Integer id) {
        return skuMapper.detail(id);
    }

    /**
     * 修改
     *
     * @param sku
     * @return
     */
    @Override
    public int update(Sku sku) {
        return skuMapper.update(sku);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public int delete(Integer id) {
        return skuMapper.delete(id);
    }
}
